import json
import xlwt
import requests
from openpyxl import Workbook
url = "https://waimaieapp.meituan.com/ad/v3/flow/r/history"
params = { "acctId": "185689039", "wmPoiId": "19273275", "token": "0ipsyEAMs1qN9sXIvCnClgm4sVHuCxvh1gMfOmoTzHe0*", "platform": "0", "bizad_cityId": "510100", "bizad_second_city_id": "510100", "bizad_third_city_id": "510113", "pageSize": "10", "pageNum": "1", "_": "1709781856290", "yodaReady": "h5", "csecplatform": "4", "csecversion": "2.4.0" }
wb=Workbook()
try:
    ws=wb.active
    ws.tile="my_data"
    ws.append(["date", "title", "price","balance","Time"])  # 表头
    for i in range(20):
        params["pageNum"]=f"{i+1}"
        response = requests.get(url, params=params)
        data_dict=response.json()
        data_dic=data_dict["data"]["flowVoList"]
        for dict in data_dic:
            date=dict["date"]
            title=dict["reason"]
            amount=dict["amount"]
            balance=dict["balance"]
            time=dict["time"]
            ws.append([date, title, amount, balance, time])
        print(f"抓取{i+1}页")
    wb.save("data.xlsx")
    print(f"抓取完成")
    wb.close()
except:
    print("操作异常")




